package com.simple.controller;

import com.simple.common.Result;
import com.simple.common.enumdto.FundEnum;
import com.simple.dto.FundEnumDTO;
import com.simple.dto.MenuDTO;
import com.simple.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName HomeController
 * @Author SimpleTree
 **/
@RestController
@RequestMapping("/home")
public class HomeController {

    @Autowired
    private HomeService homeService;

    @GetMapping("/getMenus")
    public Result getMenus() {
        List<MenuDTO> menuDTOs = new ArrayList<>();
        menuDTOs.add(new MenuDTO(0,"首页","statistics"));
        menuDTOs.add(new MenuDTO(1,"存款","amount"));
        menuDTOs.add(new MenuDTO(2,"生活","bill"));
        menuDTOs.add(new MenuDTO(3,"基金","fund"));
        menuDTOs.add(new MenuDTO(4,"收入","income"));
        menuDTOs.add(new MenuDTO(5,"银行卡","bank"));
        menuDTOs.add(new MenuDTO(6,"猪猪","user"));
        return Result.of(menuDTOs);
    }

    @GetMapping("/getTotalMoney")
    public Result getTotalMoney(@RequestParam("userId")Integer userId) {
        return Result.of(homeService.getTotalMoney(userId));
    }

    @GetMapping("/getGroupOfFund")
    public Result getGroupOfFund(@RequestParam Integer userId) {
        String username = userId == 2 ? "川" : (userId == 3 ? "园" : "");
        return Result.of(Arrays.stream(FundEnum.values())
                .filter(value -> username.equals(value.getUsername()))
                .map(value -> new FundEnumDTO(value.getCode(), value.getFundName(), value.getUsername()))
                .collect(Collectors.toList()));
    }

    @GetMapping("/getFundStatistics")
    public Result getFundStatistics(@RequestParam Integer fundCode,@RequestParam Integer userId) {
        return Result.of(homeService.getFundStatistics(FundEnum.getFundName(fundCode),userId));
    }

    @GetMapping("/getLastMonthOfBills")
    public Result getLastMonthOfBills(@RequestParam Integer userId) {
        return Result.of(homeService.getLastMonthOfBills(userId));
    }

}
